home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-05-23 | 20.4 KB | 694 lines | [TEXT/MPS ] |
- {************************************************************************************
- UCharacterDialog.p
- ************************************************************************************}
-
- UNIT UCharacterDialog;
-
- INTERFACE
-
- USES
- { • MacApp }
- UMacApp,
-
- { • Building Blocks }
- UGridView,
- UTEView,
- UDialog,
-
- UMenuItemCommand;
-
- CONST
- kMaxFonds = 100; { Max number of FONDs the FontList holds }
-
- kNormalSpacing = 0; { values for TSpaceCluster } { keystroke (UKeywordDialog) }
-
- { TextStyle mode constants — see IM v5 p269 (TESetStyle()) }
- doAlign = 64; { modify alignment }
- doPlusFace = 128; { add face to existing face }
- doMinusFace = 256; { subtract face from existing face }
- doAllAndAlign = doAll + doAlign; { doAll, and align too }
-
- { DoChoice() message numbers }
- mFontChanged = 101; { Character Dialog }
- mFontSizeChanged = 102;
- mFontFaceChanged = 103;
- mTextJustChanged = 104;
- mTextFontSizeChanged = 105;
- mListFontSizeChanged = 106;
- mSpacingChanged = 107;
-
- {###########################################################################
- Unit Initialization
- ###########################################################################}
-
- PROCEDURE InitUCharacterDialog;
-
-
- {###########################################################################
- Utility Routines
- ###########################################################################}
-
- FUNCTION SameRGBColor(color1, color2: RGBColor): BOOLEAN;
- FUNCTION SameTextStyle(style1, style2: TextStyle): BOOLEAN;
-
- { AffectTextStyle(): Uses the given source TextStyle to modify the
- given target TextStyle according to the given mode, in a manner
- similar to that used in TTEView.SetOneStyle(). Note that
- "mode" may include flags for setting the alignment, as defined
- above; if present, they are ignored. }
- PROCEDURE AffectTextStyle(
- theMode: INTEGER;
- VAR source: TextStyle; { not changed }
- VAR target: TextStyle);
-
- { AffectTextAlignment(): Uses the given source alignment to modify
- the given target alignment according to the given mode, in a
- manner similar to that used in TTEView.SetOneStyle(). Note that
- "mode" may include flags for setting the alignment, as defined
- above. }
- PROCEDURE AffectTextAlignment(
- theMode: INTEGER;
- source: INTEGER;
- VAR target: INTEGER);
-
- { AffectTextStyleAndAlign(): Uses the given source TextStyle and
- alignment to modify the given target TextStyle and alignment
- according to the given mode, in a manner similar to that used in
- TTEView.SetOneStyle(). Note that "mode" may include flags for
- setting the alignment, as defined above. }
- PROCEDURE AffectTextStyleAndAlign(
- theMode: INTEGER;
- VAR sourceTS: TextStyle; { not changed }
- sourceAlign: INTEGER;
- VAR targetTS: TextStyle;
- VAR targetAlign: INTEGER);
-
- TYPE
- FontList = ARRAY [1..kMaxFonds] OF INTEGER; { FOND resource IDs }
- FontListPtr = ^FontList;
-
-
- {###############################################################################
- TCharDialogView
- This dialog accepts a TextStyle and an alignment, allows the user to edit
- them, and allows access to the result.
- ###############################################################################}
-
- TCharDialogView = OBJECT (TDialogView)
- fSampleText: TSampleText;
- fFontListView: TFontListView;
- fSizeCluster: TSizeCluster;
- fJustCluster: TJustifyCluster;
- fFaceCluster: TFaceCluster;
-
- { PostRes(): Initialize the dialog's subview references. }
- PROCEDURE TCharDialogView.PostRes;
- OVERRIDE;
-
- { SetDialogInfo(): Initializes the dialog to reflect the given TextStyle
- record and alignment value. }
- PROCEDURE TCharDialogView.SetDialogInfo(
- theStyle: TextStyle;
- alignment: INTEGER;
- redraw: BOOLEAN);
-
- { GetDialogInfo(): Returns the dialog's current TextStyle record and
- alignment value. }
- PROCEDURE TCharDialogView.GetDialogInfo(
- VAR theStyle: TextStyle;
- VAR alignment: INTEGER);
-
- PROCEDURE TCharDialogView.SetTextFont(
- theFont: INTEGER;
- redraw: BOOLEAN);
-
- PROCEDURE TCharDialogView.SetTextSize(
- theSize: INTEGER;
- redraw: BOOLEAN);
-
- PROCEDURE TCharDialogView.SetTextFace(
- theFace: Style;
- redraw: BOOLEAN);
-
- PROCEDURE TCharDialogView.SetTextColor(
- theColor: RGBColor;
- redraw: BOOLEAN);
-
- PROCEDURE TCharDialogView.SetTextJust(
- alignment: INTEGER;
- redraw: BOOLEAN);
-
- PROCEDURE TCharDialogView.DoChoice(
- origView: TView;
- itsChoice: INTEGER);
- OVERRIDE;
- END; { TCharDialogView }
-
-
- {###############################################################################
- TSampleText
- TCharDialogView doesn't need an fTextStyle or an fAlignment field, because
- TSampleText has them.
- ###############################################################################}
-
- TSampleText = OBJECT (TStaticText)
- { PostRes(): Turn on fAutoWrap (FALSE by default in MacApp 2.0). }
- PROCEDURE TSampleText.PostRes;
- OVERRIDE;
-
- PROCEDURE TSampleText.GetTextInfo(
- VAR theStyle: TextStyle;
- VAR alignment: INTEGER);
-
- PROCEDURE TSampleText.GetTextStyle(
- VAR theStyle: TextStyle);
-
- PROCEDURE TSampleText.SetTextStyle(
- mode: INTEGER; { IM v5 p269 }
- theTextStyle: TextStyle;
- redraw: BOOLEAN);
-
- PROCEDURE TSampleText.SetTextFont(
- theFont: INTEGER;
- redraw: BOOLEAN);
-
- PROCEDURE TSampleText.SetTextSize(
- theSize: INTEGER;
- redraw: BOOLEAN);
-
- PROCEDURE TSampleText.SetTextFace(
- theFace: Style;
- redraw: BOOLEAN);
-
- PROCEDURE TSampleText.SetTextColor(
- theColor: RGBColor;
- redraw: BOOLEAN);
-
- PROCEDURE TSampleText.SetTextJust(
- alignment: INTEGER;
- redraw: BOOLEAN);
- END; { TSampleText }
-
-
-
- {###############################################################################
- TValueCheckBox
- A TValueCheckBox is just like a normal checkbox, except that it has one
- additional field: fNumber. This value is read in from the view's view
- resource, and can be accessed via access functions. It is used when the
- control is placed in a TSetCluster.
- ###############################################################################}
-
- ValueCheckBoxTemplatePtr = ^ValueCheckBoxTemplate;
- ValueCheckBoxTemplate = RECORD
- number: INTEGER;
- END; { ValueCheckBoxTemplate }
-
- TValueCheckBox = OBJECT(TCheckBox)
- fNumber: INTEGER;
-
- PROCEDURE TValueCheckBox.IRes(
- itsDocument: TDocument;
- itsSuperView: TView;
- VAR itsParams: Ptr);
- OVERRIDE;
-
- PROCEDURE TValueCheckBox.SetNumber(
- number: INTEGER);
-
- FUNCTION TValueCheckBox.GetNumber
- :INTEGER;
-
- { debugger stuff }
- {$IFC qInspector}
- PROCEDURE TValueCheckBox.Fields(
- PROCEDURE DoToField(
- fieldName: Str255;
- fieldAddr: Ptr;
- fieldType: INTEGER));
- OVERRIDE;
- {$ENDC qInspector}
- END; { TValueCheckBox }
-
-
-
- {###############################################################################
- TValueRadio
- A TValueRadio is just like a normal radio button, except that it has one
- additional field: fNumber. This value is read in from the view's view
- resource, and can be accessed via access functions. It is used when the
- control is placed in a TSetCluster.
-
- This class is actually a minor variation on TValueCheckbox.
- ###############################################################################}
-
- ValueRadioTemplatePtr = ^ValueRadioTemplate;
- ValueRadioTemplate = RECORD
- number: INTEGER;
- END; { ValueRadioTemplate }
-
- TValueRadio = OBJECT(TRadio)
- fNumber: INTEGER;
-
- PROCEDURE TValueRadio.IRes(
- itsDocument: TDocument;
- itsSuperView: TView;
- VAR itsParams: Ptr);
- OVERRIDE;
-
- PROCEDURE TValueRadio.SetNumber(
- number: INTEGER);
-
- FUNCTION TValueRadio.GetNumber
- :INTEGER;
-
- { debugger stuff }
- {$IFC qInspector}
- PROCEDURE TValueRadio.Fields(
- PROCEDURE DoToField(
- fieldName: Str255;
- fieldAddr: Ptr;
- fieldType: INTEGER));
- OVERRIDE;
- {$ENDC qInspector}
- END; { TValueRadio }
-
-
- {###############################################################################
- TSetCluster
- This class is used to manipulate a group of radio buttons and/or checkbixes
- that, together, define a set of possible values. For example, one could
- easily imagine a group of seven checkboxes, each repreenting a day of the
- week. This class can be used to combine the values of that group of
- checkboxes into a set.
-
- It is assumed that the checkboxes and/or radio buttons which are the
- subviews of this class of clusters will be of class TValueCheckBox and
- TValueRadio, respectively (see above).
-
- This class is implemented to act on a small set — no more than 31 possible
- values. That is because that's enough for a lot of uses, and beacuse its
- the biggest set for which there are no performance penalties (see MPW 3.0
- Pascal manual, p.4-18: Set Types).
-
- Note: This implementation could be improved by adding two additional
- fields: fMinValue and fMaxValue. These values could be used for
- boundary checks in DoChoice(), instead of kMinValue and kMaxValue.
-
- Also note that fSet is not initialized during PostRes(), so that it can be
- set with a call to SetTheSet() without redundancy. However, the set is
- initialized to the empty set ([]) during IRes(), to ensure stability.
- ###############################################################################}
-
- CONST
- kMinValue = 0;
- kMaxValue = 30;
- kBadValue = -32768;
- kEmptySet = -1;
-
- TYPE
- ValueRange = kMinValue..kMaxValue;
- ValueSet = SET OF ValueRange;
-
- TSetCluster = OBJECT(TCluster)
- fSet: ValueSet; { the current set }
-
- { IRes(): Sets fSet to []. }
- PROCEDURE TSetCluster.IRes(
- itsDocument: TDocument;
- itsSuperView: TView;
- VAR itsParams: Ptr);
- OVERRIDE;
-
- PROCEDURE TSetCluster.SetTheSet(
- theSet: ValueSet;
- redraw: BOOLEAN);
-
- FUNCTION TSetCluster.GetTheSet
- : ValueSet;
-
- { DoCheckBoxHit(): Handles mCheckBoxHit messages. Can alter the
- values of origView and itsChoice. }
- PROCEDURE TSetCluster.DoCheckBoxHit(
- VAR origView: TView;
- VAR itsChoice: INTEGER);
-
- { DoRadioHit(): Handles mRadioHit messages. Can alter the values
- of origView and itsChoice. }
- PROCEDURE TSetCluster.DoRadioHit(
- VAR origView: TView;
- VAR itsChoice: INTEGER);
-
- { DoChoice(): maintains fSet. }
- PROCEDURE TSetCluster.DoChoice(
- origView: TView;
- itsChoice: INTEGER);
- OVERRIDE;
-
- { debugger stuff }
- {$IFC qInspector}
- PROCEDURE TSetCluster.Fields(
- PROCEDURE DoToField(
- fieldName: Str255;
- fieldAddr: Ptr;
- fieldType: INTEGER));
- OVERRIDE;
- {$ENDC qInspector}
- END; { TSetCluster }
-
-
-
- {###############################################################################
- TValueRadioCluster
- This class is, in most respects, just like a regular cluster. Its special
- function is that, if it contains a bunch of TValueRadio controls, it
- can find the 'number' of the currently-selected TValueRadio control.
- ###############################################################################}
-
- TValueRadioCluster = OBJECT(TCluster)
- PROCEDURE TValueRadioCluster.SetNumber(
- number: INTEGER;
- redraw: BOOLEAN);
-
- FUNCTION TValueRadioCluster.GetNumber
- :INTEGER;
-
- { debugger stuff }
- {$IFC qInspector}
- PROCEDURE TValueRadioCluster.Fields(
- PROCEDURE DoToField(
- fieldName: Str255;
- fieldAddr: Ptr;
- fieldType: INTEGER));
- OVERRIDE;
- {$ENDC qInspector}
- END; { TValueRadioCluster }
-
-
- {###############################################################################
- TJustifyCluster
- ###############################################################################}
-
- TJustifyCluster = OBJECT (TValueRadioCluster)
- fSampleText: TSampleText;
-
- { PostRes(): Initialize the dialog's subview references. }
- PROCEDURE TJustifyCluster.PostRes;
- OVERRIDE;
-
- PROCEDURE TJustifyCluster.DoChoice(
- origView: TView;
- itsChoice: INTEGER);
- OVERRIDE;
-
- PROCEDURE TJustifyCluster.SetTextJust(
- alignment: INTEGER;
- redraw: BOOLEAN);
- END; { TJustifyCluster }
-
- {###############################################################################
- TStyleCluster
- This class provides an interface between the TFaceCluster class, which
- wants to manipulate QuickDraw styles, and TSetCluster, which wants to
- manipulate ValueSets (see IM v1 p201).
- ###############################################################################}
-
- TStyleCluster = OBJECT (TSetCluster)
- PROCEDURE TStyleCluster.SetTextFace(
- theFace: Style;
- redraw: BOOLEAN);
-
- FUNCTION TStyleCluster.GetTextFace
- : Style;
- END;
-
- {###############################################################################
- TSpaceCluster
- This class provides an interface between the TFaceCluster class, which
- wants to manipulate QuickDraw styles, and TValueRadioCluster, which wants
- to manipulate only single integers.
- ###############################################################################}
-
- TSpaceCluster = OBJECT (TValueRadioCluster)
- PROCEDURE TSpaceCluster.SetTextFace(
- theFace: Style;
- redraw: BOOLEAN);
-
- FUNCTION TSpaceCluster.GetTextFace
- : Style;
- END; { TSpaceCluster }
-
-
- {###############################################################################
- TFaceCluster
- This implementation relies on these facts being true:
- • all of the controls in the TStyleCluster are checkboxes
- • all of the controls in the TSpaceCluster are radio buttons
- • the TFaceCluster contains no other controls
-
- With these things being true, we know that whenever the TFaceCluster's
- DoChoice() method gets told about a mCheckBoxHit, we know it happened in
- the style cluster. Likewise, if it gets a mRadioHit message, we know
- it happened in the TSpaceCluster.
- ###############################################################################}
-
- TFaceCluster = OBJECT (TCluster)
- fStyleCluster: TStyleCluster;
- fSpaceCluster: TSpaceCluster;
- fSampleText: TSampleText;
-
- { PostRes(): Initialize the dialog's subview references. }
- PROCEDURE TFaceCluster.PostRes;
- OVERRIDE;
-
- PROCEDURE TFaceCluster.SetTextFace(
- theFace: Style;
- redraw: BOOLEAN);
-
- FUNCTION TFaceCluster.GetTextFace
- : Style;
-
- { DoChoice(): Handles all manipulations of the style and spacing
- clusters, which are subviews of SELF. }
- PROCEDURE TFaceCluster.DoChoice(
- origView: TView;
- itsChoice: INTEGER);
- OVERRIDE;
- END;
-
-
- {###############################################################################
- TFontListView
- ###############################################################################}
-
- TFontListView = OBJECT (TTextListView)
- fFontList: FontListPtr; { font resource ids }
-
- { PostRes(): Calls InitFontList(). }
- PROCEDURE TFontListView.PostRes;
- OVERRIDE;
-
- PROCEDURE TFontListView.InitFontList;
-
- PROCEDURE TFontListView.Free;
- OVERRIDE;
-
- PROCEDURE TFontListView.GetItemText(
- anItem: INTEGER;
- VAR aString: Str255);
- OVERRIDE;
-
- PROCEDURE TFontListView.SelectItem(
- anItem: INTEGER;
- extendSelection,
- highlight,
- select: BOOLEAN);
- OVERRIDE;
-
- FUNCTION TFontListView.GetTextFont
- :INTEGER;
-
- PROCEDURE TFontListView.SetTextFont(
- theFont: INTEGER;
- redraw: BOOLEAN);
-
- {$IFC qInspector}
- PROCEDURE TFontListView.Fields(PROCEDURE
- DoToField(fieldName: Str255;
- fieldAddr: Ptr;
- fieldType: INTEGER)); OVERRIDE;
- {$ENDC qInspector}
- END;
-
-
- {###############################################################################
- TSizeListView
- ###############################################################################}
-
- TSizeListView = OBJECT (TTextListView)
-
- fFondID: INTEGER;
-
- FUNCTION TSizeListView.GetItemSize(
- anItem: INTEGER)
- :INTEGER;
-
- FUNCTION TSizeListView.FindSizeItem(
- theSize: INTEGER)
- :INTEGER;
-
- FUNCTION TSizeListView.GetTextSize
- :INTEGER;
-
- PROCEDURE TSizeListView.SetTextSize(
- theSize: INTEGER;
- redraw: BOOLEAN);
-
- PROCEDURE TSizeListView.GetItemText(
- anItem: INTEGER;
- VAR aString: Str255);
- OVERRIDE;
-
- PROCEDURE TSizeListView.SetNumberOfItems(
- aNumber: INTEGER);
-
- PROCEDURE TSizeListView.InstallFontFamily(
- theFondID: INTEGER);
-
- PROCEDURE TSizeListView.SelectItem(
- anItem: INTEGER;
- extendSelection: BOOLEAN;
- highlight: BOOLEAN;
- select: BOOLEAN);
- OVERRIDE;
-
- PROCEDURE TSizeListView.Fields(PROCEDURE
- DoToField(fieldName: Str255;
- fieldAddr: Ptr;
- fieldType: INTEGER)); OVERRIDE;
- END;
-
-
- {###############################################################################
- TSizeText
- ###############################################################################}
-
- TSizeText = OBJECT (TNumberText)
-
- FUNCTION TSizeText.GetTextSize
- :INTEGER;
-
- PROCEDURE TSizeText.SetTextSize(
- theSize: INTEGER;
- redraw: BOOLEAN);
-
- FUNCTION TSizeText.Validate: LONGINT;
- OVERRIDE;
-
- END;
-
-
- {###############################################################################
- TSizeCluster
- ###############################################################################}
-
- TSizeCluster = OBJECT (TCluster)
- fSizeText: TSizeText;
- fSizeListView: TSizeListView;
-
- { PostRes(): Initialize the dialog's subview references. }
- PROCEDURE TSizeCluster.PostRes;
- OVERRIDE;
-
- FUNCTION TSizeCluster.GetTextSize
- :INTEGER;
-
- PROCEDURE TSizeCluster.SetTextSize(
- theSize: INTEGER;
- redraw: BOOLEAN);
-
- PROCEDURE TSizeCluster.SetTextFont(
- theFont: INTEGER;
- redraw: BOOLEAN);
-
- PROCEDURE TSizeCluster.DoChoice(
- origView: TView;
- itsChoice: INTEGER);
- OVERRIDE;
- END;
-
-
- {###########################################################################
- TCharacterDialogCmd
- This command displays the Character dialog. It is a subclass of
- TMacAppDialogCmd, which is defined in UMenuItemCommand.
- ###########################################################################}
-
- TCharacterDialogCmd = OBJECT(TMacAppDialogCmd)
- fTextStyle: TextStyle;
- fAlignment: INTEGER;
-
- PROCEDURE TCharacterDialogCmd.ICharacterDialogCmd(
- itsCmdNumber: CmdNumber;
- itsDocument: TDocument;
- itsView: TView;
- itsScroller: TScroller;
- itsTextStyle: TextStyle;
- itsAlignment: INTEGER);
-
- { InitTheDialog(): Initializes the dialog to reflect the command's
- TextStyle and alignment values (which were set in an override of
- InitMenuItemCommand()). }
- PROCEDURE TCharacterDialogCmd.InitTheDialog;
- OVERRIDE;
-
- {$IFC qInspector}
- PROCEDURE TCharacterDialogCmd.Fields(
- PROCEDURE DoToField(
- fieldName: Str255;
- fieldAddr: Ptr;
- fieldType: INTEGER));
- OVERRIDE;
- {$ENDC qInspector}
- END; { TCharacterDialogCmd }
-
-
- {###########################################################################
- TColorDialogCmd
- This command displays the Color Picker dialog.
- ###########################################################################}
-
- TColorDialogCmd = OBJECT(TToolboxDialogCmd)
- fInitialColor: RGBColor;
- fResultColor: RGBColor;
- fPromptID: INTEGER;
-
- PROCEDURE TColorDialogCmd.IColorDialogCmd(
- itsCmdNumber: CmdNumber;
- itsDocument: TDocument;
- itsView: TView;
- itsScroller: TScroller;
- itsInitialColor: RGBColor;
- itsPromptID: INTEGER);
-
- { PoseTheDialog(): Calls the Color Picker Package routine GetColor(),
- which builds its own dialog, using its own filter, dismissers, etc. }
- PROCEDURE TColorDialogCmd.PoseTheDialog;
- OVERRIDE;
-
- {$IFC qInspector}
- PROCEDURE TColorDialogCmd.Fields(
- PROCEDURE DoToField(
- fieldName: Str255;
- fieldAddr: Ptr;
- fieldType: INTEGER));
- OVERRIDE;
- {$ENDC qInspector}
- END; { TColorDialogCmd }
-
-
- IMPLEMENTATION
-
- {$I UCharacterDialog.inc1.p}
-
- END.